首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏SnailTyan

    Diameter of Binary Tree

    Solution /** * Definition for a binary tree node.

    45920发布于 2019-05-25
  • 来自专栏SnailTyan

    Binary Tree Paths

    Solution Recursive /** * Definition for a binary tree node. searchPath(root->right, s, result); } } }; Iterative /** * Definition for a binary tree node

    41510发布于 2019-05-25
  • 来自专栏皮皮星球

    Tree - 257. Binary Tree Paths

    Binary Tree Paths Given a binary tree, return all root-to-leaf paths. 代码: go: /** * Definition for a binary tree node.

    56220发布于 2020-09-23
  • 来自专栏皮皮星球

    Tree - 226. Invert Binary Tree

    Invert Binary Tree Invert a binary tree. / \ 7 2 / \ / \ 9 6 3 1 思路: 递归求解翻转每个不为nil的节点 代码: go: /** * Definition for a binary tree node

    68620发布于 2020-09-23
  • 来自专栏皮皮星球

    Tree - 110. Balanced Binary Tree

    Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the Example 1: Given the following tree [3,9,20,null,null,15,7]: 3 / \ 9 20 / \ 15 7 Example 2: Given the following tree [1,2,2,3,3,null,null,4,4]: 1 / \ 2 2 / \ 代码: go: /** * Definition for a binary tree node.

    52610发布于 2020-09-23
  • 来自专栏calmound

    Binary Tree Preorder Traversal

    二叉树的前序遍历 递归实现 /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode

    63180发布于 2018-04-17
  • 来自专栏calmound

    Maximum Depth of Binary Tree

    问题:二叉树的最深深度 class Solution { public: void dfs(TreeNode *root,int step,int &MAX) { if(root==NULL) { if(MAX<step) MAX=step; return ; } dfs(root->left,step+1); dfs(root->right,step+1);

    49730发布于 2018-04-17
  • 来自专栏给永远比拿愉快

    Leetcode: Balanced Binary Tree

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the C++参考示例代码: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left

    40920发布于 2019-01-22
  • 来自专栏SnailTyan

    Binary Tree Inorder Traversal

    问题描述 Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. 2. /** * Definition for a binary tree node.

    38210发布于 2019-05-25
  • 来自专栏calmound

    Minimum Depth of Binary Tree

    题意:二叉树的最小深度 注意   1.当root为空的时候直接返回0,因为MIN赋值很大,所以如果不单独预判的话会返回MIN         2.判断树的深度应该到叶子节点,也就是左右子结点都为空的那个结点         3.树的深度的根节点深度为1 class Solution { public: void dfs(TreeNode *root,int &MIN,int step) { if(root==NULL) return ; if(root->

    69470发布于 2018-04-17
  • 来自专栏蛮三刀的后端开发专栏

    Minimum Depth of Binary Tree

    这题有意思的是,并不能直接将求最大深度的max改为min就完了,有很多坑在里面。一开始我以为只要将[],[0],[1,2]等情况考虑掉就可以了,其实在只有一边又子节点的情况下,是仍然需要遍历的。 例如:

    44520发布于 2019-03-26
  • 来自专栏皮皮星球

    Tree - 111. Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. Example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its 代码: go: /** * Definition for a binary tree node.

    52520发布于 2020-09-23
  • 来自专栏皮皮星球

    Tree - 145. Binary Tree Postorder Traversal

    Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' values 代码: go: /** * Definition for a binary tree node.

    52810发布于 2020-09-23
  • 来自专栏calmound

    Binary Tree Inorder Traversal

    问题:二叉树中序遍历 递归实现 /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode

    59560发布于 2018-04-17
  • 来自专栏皮皮星球

    Tree - 297. Serialize and Deserialize Binary Tree

    Serialize and Deserialize Binary Tree Serialization is the process of converting a data structure or Design an algorithm to serialize and deserialize a binary tree. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure. ,null,null,4,5]" Clarification: The above format is the same as how LeetCode serializes a binary tree

    48010发布于 2020-09-23
  • 来自专栏搬砖记录

    44 Binary Search Tree to Greater Sum Tree

    题目 Given the root of a binary search tree with distinct values, modify it so that every node has a new value equal to the sum of the values of the original tree that are greater than or equal to node.val As a reminder, a binary search tree is a tree that satisfies these constraints: The left subtree of a Both the left and right subtrees must also be binary search trees. Example 1: ? The given tree is a binary search tree. 分析 题意:从右到左、下到上累加和,赋给当前节点。

    61230发布于 2021-08-18
  • 来自专栏SnailTyan

    Binary Tree Preorder Traversal

    问题描述 Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. 2. /** * Definition for a binary tree node.

    35620发布于 2019-05-25
  • 来自专栏尾尾部落

    Minimum Depth of Binary Tree

    链接:https://leetcode.com/problems/minimum-depth-of-binary-tree/description/ 难度:Easy 题目:111. Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. 思路:本题与Maximum Depth of Binary Tree类似,依旧用递归的方法来求解。 参考代码: Java /** * Definition for a binary tree node. root.right)); } } 上一篇 下一篇 版权属于: 尾尾部落 原文地址: https://weiweiblog.cn/minimum-depth-of-binary-tree

    56960发布于 2018-09-04
  • 来自专栏搬砖记录

    50 Maximum Binary Tree

    A maximum tree building on this array is defined as follow: The root is the maximum number in the array The left subtree is the maximum tree constructed from left part subarray divided by the maximum number Construct the maximum tree by the given array and output the root node of this tree. Example 1: Input: [3,2,1,6,0,5] Output: return the tree root node representing the following tree: 解答 /** * Definition for a binary tree node.

    34520发布于 2021-08-18
  • 来自专栏皮皮星球

    Tree - 173. Binary Search Tree Iterator

    Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). 代码: go: /** * Definition for a binary tree node.

    44420发布于 2020-09-23
领券